package nayasis.common.xml;

import java.io.IOException;
import java.util.List;

import nayasis.common.conf.NConfigulator;

import org.jdom2.Element;
import org.jdom2.JDOMException;

public class Test {
	
	public static void main( String[] args ) throws JDOMException, IOException {
		
		XmlBuilder xmlBuilder = new XmlBuilder( "resource/conf/config.xml" );
		
		List<Element> elements = xmlBuilder.getElements( "/EmuLoader/emul" );
		
		System.out.println( elements.size() );
		System.out.println( elements.get(0).getAttributeValue("category") );

		System.out.println( xmlBuilder.getElement("/EmuLoader/emul[1]").getAttributeValue("category") );
		System.out.println( xmlBuilder.getAttribute("//emul/@category") );
		System.out.println( xmlBuilder.getAttributeValue("//emul/@category") );
		
		for( Element e : elements ) {
			
			System.out.printf( "This Element has name '%s' and text '%s' and attrubute %s \n", e.getName(), e.getValue(), e.getAttribute("category") );
			
		}
		
		System.out.println( NConfigulator.getElementValue( "/common/database/manager[@name='main']/class" ) );
		
		
		Element element = NConfigulator.getElement( String.format("/common/database/manager[@name='%s']", "main") );
		
		System.out.println( element.getChild( "class" ).getValue() );
		System.out.println( element.getChild( "url" ).getValue() );

		element = NConfigulator.getElement( "/common/database/manager[@default='true']" );
		System.out.println( element.getAttributeValue("name") );
		
	}

}
